class Address < ActiveRecord::Base

  validates_numericality_of :house_number,
                            :only_integer => true,
                            :greater_than_or_equal_to => 0

  validates_presence_of :name,
                        :street,
                        :house_number,
                        :city,
                        :postal_code,
                        :telephone_number

  validates_format_of :postal_code,
                      :with => /^\s*[0-9]{4}\s*[a-z]{2}\s*$/i,
                      :message => 'is geen geldige Nederlandse postcode.'


  belongs_to :user


  # Retourneert bijvoorbeeld:
  # 1234AB Amsterdam Straat 5b
  def human_readable
    postal_code + ', ' + city + ', ' + street + ' ' + house_number.to_s + house_number_addition
  end

end
